package com.cheung.leetcode.normal;

import java.util.HashMap;
import java.util.Map;

public class LC6 {

    public static String convert(String s, int numRows) {
        if (numRows == 1) {
            return s;
        }
        int index = 0;
        int flag = 1;
        Map<Integer, String> hash = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            if (index == numRows || index + flag == 0) {
                flag = -flag;
            }
            index += flag;
            hash.put(index, hash.getOrDefault(index, "") + s.charAt(i));
        }

        StringBuilder sb = new StringBuilder();
        for (String value : hash.values()) {
            sb.append(value);
        }

        return sb.toString();
    }

    public static void main(String[] args) {
        String s = "ABCDEFG";
        int numRows = 1;
        System.out.println(convert(s, numRows));


    }
}
